<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>闭包的应用</title>
</head>

<body>
    <ul>
        <li>曹操</li>
        <li>项羽</li>
        <li>张飞</li>
        <li>刘备</li>
    </ul>
    <script>
        //获取多个li
        var lists = document.getElementsByTagName("li");
        for (var i = 0; i < lists.length; i++) {
            //分别对每一个LI触发点击事件
            lists[i].onclick = (function(s) {
                return function() {
                    lists[s].style.color = "red"
                };
            })(i);
        }
    </script>
</body>

</html>